import { BasicPageParams } from '../model/baseModel';
import type { TeacherListResultModel } from './types/teacher';
import { defHttp } from '/@/utils/http/axios';
import type { Result } from '/#/axios';

enum Api {
  ADMIN_TEACHER_PREFIX = '/admin/teacher',
  TEACHER_LIST = '/admin/teacher/getTeacherList',
  TEACHER_DELETE = '/admin/teacher/deleteTeacherById',
  TEACHER_ADD = '/addTeacher',
  TEACHER_IS_NAME_EXISTS = '/isNameExists',
  TEACHER_INFO_BY_ID = '/getTeacherInfoBYId',
  TEACHER_UPDATE = '/updateTeacher',
  TEACHER_DELETE_BATH = '/deleteTeacherByIds',
}
/**
 * @description: 获取教师列表
 */
export const teacherListApi = (params: BasicPageParams) =>
  defHttp.get<TeacherListResultModel>({
    url: `${Api.TEACHER_LIST}`,
    params,
    headers: {
      ignoreCancelToken: true,
    },
  });
/**
 * @description: 删除教师
 */
export const teacherDeleteApiById = (params: number) =>
  defHttp.get<Result>(
    {
      url: `${Api.TEACHER_DELETE}/${params}`,
      headers: {
        //忽略取消令牌
        ignoreCancelToken: true,
      },
    },
    {
      successMessageMode: 'message',
    },
  );
/**
 * @description: 批量删除教师
 */
export const deleteTeacherByIds = (data) =>
  defHttp.post<Result>(
    {
      url: `${Api.ADMIN_TEACHER_PREFIX}${Api.TEACHER_DELETE_BATH}`,
      data,
      headers: {
        //忽略取消令牌
        ignoreCancelToken: true,
      },
    },
    {
      successMessageMode: 'message',
    },
  );
/**
 * @description: 添加教师
 */
export const teacherAdd = (data) =>
  defHttp.post<Result>(
    {
      url: `${Api.ADMIN_TEACHER_PREFIX}${Api.TEACHER_ADD}`,
      data,
      headers: {
        ignoreCancelToken: true,
      },
    },
    {
      successMessageMode: 'message',
    },
  );
/**
 * @description: 异步判断教师名是否存在
 */
export const isNameExist = (name: string) =>
  defHttp.get<Result>(
    {
      url: `${Api.ADMIN_TEACHER_PREFIX}${Api.TEACHER_IS_NAME_EXISTS}?name=${name}`,
    },
    {
      errorMessageMode: 'none',
    },
  );
/**
 * @description: 根据id查询教师信息
 */
export const teacherInfoById = (id: string) => {
  return defHttp.get<Result>(
    {
      url: `${Api.ADMIN_TEACHER_PREFIX}${Api.TEACHER_INFO_BY_ID}/${id}`,
    },
    {
      errorMessageMode: 'none',
    },
  );
};
/**
 * @description: 更改教师信息
 */
export const updateTeacher = (data) =>
  defHttp.put<Result>(
    {
      url: `${Api.ADMIN_TEACHER_PREFIX}${Api.TEACHER_UPDATE}`,
      data,
    },
    {
      successMessageMode: 'message',
    },
  );
